import {applicationJsonHeader, doGet, doPost} from "@/net/axios-request.ts";
import {userTokenHeader} from "@/utils/auth-utils.ts";

export interface Carousel {
    carouselId: number,
    imageUrl: string,
    redirectUrl: string,
    priority: number,
    isActive: number,
    expireTime: string
}

export function getEmptyCarousel(): Carousel {
    return {
        carouselId: 0, expireTime: new Date().toUTCString(), imageUrl: "", isActive: 1, priority: 0, redirectUrl: ""
    }
}

export async function getAllCarousels() {
    return (await doGet<Carousel[]>("/api/carousel/all", {}, {})).data
}

export async function saveOrUpdateCarousel(carousel: Carousel) {
    return await doPost("/api/carousel/save", {...userTokenHeader(), ...applicationJsonHeader}, {...carousel})
}